package com.ysqcould.curriculum.service.impl;

import java.util.List;

import com.ysqcould.common.utils.DateUtils;
import com.ysqcould.curriculum.domain.CourseTag;
import com.ysqcould.curriculum.domain.CourseTeacher;
import com.ysqcould.curriculum.domain.CourseType;
import com.ysqcould.curriculum.mapper.CourseTagMapper;
import com.ysqcould.curriculum.mapper.CourseTeacherMapper;
import com.ysqcould.curriculum.mapper.CourseTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ysqcould.curriculum.mapper.CourseMapper;
import com.ysqcould.curriculum.domain.Course;
import com.ysqcould.curriculum.service.ICourseService;

/**
 * 课程视频Service业务层处理
 * 
 * @author jcd
 * @date 2022-09-27
 */
@Service
public class CourseServiceImpl implements ICourseService 
{
    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private CourseTagMapper tagMapper;

    @Autowired
    private CourseTeacherMapper teacherMapper;

    @Autowired
    private CourseTypeMapper typeMapper;

    /**
     * 查询课程视频
     * 
     * @param id 课程视频主键
     * @return 课程视频
     */
    @Override
    public Course selectCourseById(Long id)
    {
        return courseMapper.selectCourseById(id);
    }

    /**
     * 查询课程视频列表
     * 
     * @param course 课程视频
     * @return 课程视频
     */
    @Override
    public List<Course> selectCourseList(Course course)
    {
        return courseMapper.selectCourseList(course);
    }

    /**
     * 新增课程视频
     * 
     * @param course 课程视频
     * @return 结果
     */
    @Override
    public int insertCourse(Course course)
    {
        course.setCreateTime(DateUtils.getNowDate());
        return courseMapper.insertCourse(course);
    }

    /**
     * 修改课程视频
     * 
     * @param course 课程视频
     * @return 结果
     */
    @Override
    public int updateCourse(Course course)
    {
        course.setUpdateTime(DateUtils.getNowDate());
        return courseMapper.updateCourse(course);
    }

    /**
     * 批量删除课程视频
     * 
     * @param ids 需要删除的课程视频主键
     * @return 结果
     */
    @Override
    public int deleteCourseByIds(Long[] ids)
    {
        return courseMapper.deleteCourseByIds(ids);
    }

    /**
     * 删除课程视频信息
     * 
     * @param id 课程视频主键
     * @return 结果
     */
    @Override
    public int deleteCourseById(Long id)
    {
        return courseMapper.deleteCourseById(id);
    }

    /**
     * 课程分类
     * @param userId
     * @return
     */
    @Override
    public List<CourseType> getType(Long userId) {
        Long asId=null;
        if (userId==1){
            userId=asId;
        }
        CourseType type=new CourseType();
        type.setAsId(userId);
        return typeMapper.selectCourseTypeList(type);
    }

    /**
     * 课程标签
     * @param userId
     * @return
     */
    @Override
    public List<CourseTag> getTag(Long userId) {
        Long asId=null;
        if (userId==1){
            userId=asId;
        }
        CourseTag tag=new CourseTag();
        tag.setAsId(userId);
        return tagMapper.selectCourseTagList(tag);
    }

    /**
     * 课程讲师
     * @param userId
     * @return
     */
    @Override
    public List<CourseTeacher> getTeacher(Long userId) {
        Long asId=null;
        if (userId==1){
            userId=asId;
        }
        CourseTeacher teacher=new CourseTeacher();
        teacher.setAsId(userId);
        return teacherMapper.selectCourseTeacherList(teacher);
    }

    /**
     * 修改课程
     * @param course
     * @return
     */
    @Override
    public int changeStatus(Course course) {
        Course c = courseMapper.selectCourseById(course.getId());
        c.setStatus(course.getStatus());
        return courseMapper.updateCourse(c);
    }

    @Override
    public int changeIsShow(Course course) {
        Course c = courseMapper.selectCourseById(course.getId());
        c.setIsSlideShow(course.getIsSlideShow());
        return courseMapper.updateCourse(c);
    }


}
